package com.wanlian.router.ui.main.yun;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.TextView;
import android.widget.Toast;

import com.smart.android.widget.EditTextWithClear;
import com.wanlian.router.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Hyu on 2018/10/10.
 * Email: fvaryu@163.com
 */
public class InputDialog extends Dialog {
    @BindView(R.id.et_name)
    EditTextWithClear et_name;

    @BindView(R.id.tv_title)
    TextView tv_title;
    private String title;
    private String hidden;

    public void setHidden(String hidden) {
        this.hidden = hidden;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    private OnNameInputListener mOnNameInputListener;

    public void setOnNameInputListener(OnNameInputListener onNameInputListener) {
        mOnNameInputListener = onNameInputListener;
    }

    public interface OnNameInputListener {
        void onNameInput(Dialog dialog, String name);
    }

    public InputDialog(@NonNull Context context) {
        super(context, R.style.UpgradeDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_rename);
        ButterKnife.bind(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (hidden != null) {
            et_name.setHint(hidden);
        }

        if (title != null) {
            tv_title.setText(title);
        }
    }


    @OnClick(R.id.tv_cancel)
    void cancel_() {
        dismiss();
    }

    @OnClick(R.id.tv_next)
    void next() {

        if (et_name.getText() == null || TextUtils.isEmpty(et_name.getText().toString().trim())) {
            Toast.makeText(getContext(), "请输入文件名", Toast.LENGTH_SHORT).show();
            return;
        }
        if (mOnNameInputListener != null) {
            mOnNameInputListener.onNameInput(this,et_name.getText().toString().trim());
        }
    }
}
